<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>

    <meta charset="utf-8">
<title>资讯添加/修改</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base_new.css,../js/jqueryui/jquery-ui.min.css'); }
    {php echo Common::getScript("jquery.upload.js,product_add.js,choose.js,imageup.js,jqueryui/jquery-ui.min.js"); }
</head>

<body>

    <table class="content-tab">
        <tr>
            <td width="119px" class="content-lt-td"  valign="top">
                {template 'stourtravel/public/leftnav'}
                <!--右侧内容区-->
            </td>
            <td valign="top" class="content-rt-td ">
                <form method="post" name="product_frm" id="product_frm" head_script=m2CuKC >
                    <div class="cfg-header-bar">
                        <div class="cfg-header-tab" id="nav">
                            <span class="item on">基础信息</span>
                            <span class="item" data-id="tupian">资讯附件</span>
                            <span class="item" data-id="youhua">优化设置</span>
                            <span class="item" data-id="extend">扩展设置</span>
                        </div>
                        <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                    </div>
                    <div class="manage-nr">

                        <!--基础信息开始-->
                        <div class="product-add-div">
                            <ul class="info-item-block">
<!--                                <li>-->
<!--                                    <span class="item-hd">站点：</span>-->
<!--                                    <div class="item-bd">-->
<!--                                        <div class="select-box w200">-->
<!--                                            <select name="webid" class="select">-->
<!--                                                <option value="0" {if $info['webid']==0}selected="selected"{/if}>主站</option>-->
<!--                                                {loop $weblist $k}-->
<!--                                                <option value="{$k['webid']}" {if $info['webid']==$k['webid']}selected="selected"{/if} >{$k['webname']}</option>-->
<!--                                                {/loop}-->
<!--                                            </select>-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                </li>-->
                                <li>
                                    <span class="item-hd">分类：</span>
                                    <div class="item-bd">
                                        <div class="select-box w150">
                                            <select name="category_one" onchange="getCategoryNext(this.options[this.options.selectedIndex].value,1)" class="select">
                                                <option value="0" {if empty($info['category_one'])}selected="selected"{/if}>请选择</option>
                                                {loop $category_first_list $category}
                                                <option value="{$category['id']}" {if ($info['category_one'] == $category['id'])}selected="selected"{/if}>{$category['attrname']}</option>
                                                {/loop}
                                            </select>
                                        </div>
                                        <div class="select-box w150 ml-5">
                                            <select name="category_two" id="category_two" class="select">
                                                    <option value="0" {if empty($info['category_two'])}selected="selected"{/if}>请选择</option>
                                                {loop $category_second $category_two}
                                                    <option value="{$category_two['id']}" {if ($info['category_two'] == $category_two['id'])}selected="selected"{/if}>{$category_two['attrname']}</option>
                                                {/loop}
                                            </select>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">标题：</span>
                                    <div class="item-bd">
                                        <input type="text" name="title" id="articlename" class="input-text w900" value="{$info['title']}" />
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">内容: </span>
                                    <div class="item-bd">
                                        {php Common::getEditor('content',$info['content'],$sysconfig['cfg_admin_htmleditor_width'],400);}
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">摘要：</span>
                                    <div class="item-bd">
                                        <textarea class="textarea w900"  name="summary" id="" cols="" rows="">{$info['summary']}</textarea>
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">显示模版：</span>
                                    <div class="item-bd">
                                        <div class="select-box w150">
                                            <select name="templet" class="select">
                                                <option value="" {if empty($info['templet'])}selected="selected"{/if}>标准模板</option>
                                                {loop $templetlist $r}
                                                <option value="{$r['path']}" {if ($info['templet']==$r['path'])}selected="selected"{/if}>{$r['templetname']}</option>
                                                {/loop}
                                            </select>
                                        </div>
                                    </div>
                                </li>
                                <li>
                                  <span class="item-hd">封面图片{Common::get_help_icon('yingyong_pic_fengmian')}：</span>
                                  <div class="item-bd">
                                      <label class="check-label"><input type="checkbox" name="allow" value="usecontentpic">使用文章内图片作封面</label>
                                  </div>
                                </li>
                                <li>
                                <span class="item-hd">站内信通知{Common::get_help_icon('web_notifly_contetn')}：</span>
                                <div class="item-bd">
                                    <label class="radio-label"><input type="radio" name="has_msg" value="1" {if $info['has_msg']==1}checked="checked"{/if}/> 是</label>
                                    <label class="radio-label ml-20"><input type="radio" name="has_msg" {if $info['has_msg']==0}checked="checked"{/if} value="0"/> 否</label>
                                </div>
                                </li>
                            </ul>
                            <div class="line"></div>
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">阅读量：</span>
                                    <div class="item-bd">
                                        <input type="text" name="shownum" id="shownum"  class="input-text w100" value="{$info['shownum']}">
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">作者：</span>
                                    <div class="item-bd">
                                        <input type="text" name="author" id="author" class="input-text w300" value="{$info['author']}" />
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">文章来源：</span>
                                    <div class="item-bd">
                                        <input type="text" name="comefrom" id="comefrom" class="input-text w300" value="{$info['comefrom']}" />
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">来源网址：</span>
                                    <div class="item-bd">
                                        <input type="text" name="fromsite" id="fromsite" class="input-text w300" value="{$info['fromsite']}" />
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">前台隐藏：</span>
                                    <div class="item-bd">
                                        <label class="radio-label"><input type="radio" name="ishidden"  {if $info['ishidden']==0}checked="checked"{/if} value="0">显示</label>
                                        <label class="radio-label ml-20"><input type="radio" name="ishidden"  {if $info['ishidden']==1}checked="checked"{/if} value="1">隐藏</label>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="product-add-div" data-id="tupian">
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">图片：</span>
                                    <div class="item-bd">
                                        <div class="">
                                            <div id="pic_btn" class="btn btn-primary radius size-S mt-3">上传图片</div>
                                            <span class="item-text c-999 ml-10">建议上传尺寸 PC750*527px UNIAPP750*190px</span>
                                        </div>
                                        <div class="up-list-div">
                                            <input type="hidden" class="headimgindex" name="imgheadindex" value=""/>
                                            <input type="hidden" name="litpic" id="litpic" value="{$info['litpic']}"/>
                                            <div class="lh-24 mt-5 c-999">注意：图片可以拖动排序</div>
                                            <ul class="pic-sel">

                                            </ul>
                                            <script>
                                                $( ".pic-sel" ).sortable();
                                            </script>
                                        </div>
                                        <span class="tip-img-size"></span>
                                    </div>
                                </li>
<!--                                <li>
                                    <span class="item-hd">附件：</span>
                                    <div class="item-bd">
                                        <div class="up-file-div">
                                            <div id="attach_btn" class="btn-file mt-4">上传附件</div>
                                            <input type="hidden" name="attachment" id="attachment" value="{$info['attachment']}">
                                        </div>
                                        <div id="doclist" class="doclist">
                                            {if !empty($info['attachment'])}
                                            <a href="{$cmsurl}{$info['attachment']}">查看附件</a>
                                            <a href="javascript:;" onclick="delAttach()">删除</a>
                                            {/if}
                                        </div>
                                    </div>
                                </li>-->
                            </ul>
                        </div>
                        <div class="product-add-div" data-id="youhua">
                            <ul class="info-item-block">
                                <li>
                                    <span class="item-hd">优化标题：</span>
                                    <div class="item-bd">
                                        <input type="text" name="seotitle" id="seotitle" class="input-text w900" value="{$info['seotitle']}" >
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">Tag词：</span>
                                    <div class="item-bd">
                                        <input type="text" id="tagword" name="tagword" class="input-text w500" value="{$info['tagword']}" >
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">关键词：</span>
                                    <div class="item-bd">
                                        <input type="text" name="keyword" id="keyword" name="keyword" class="input-text w500" value="{$info['keyword']}">
                                    </div>
                                </li>
                                <li>
                                    <span class="item-hd">页面描述：</span>
                                    <div class="item-bd">
                                        <textarea class="textarea w900"  name="description" id="description" cols="" rows="">{$info['description']}</textarea>
                                    </div>
                                </li>
                            </ul>
                        </div>
                        <div class="product-add-div" data-id="extend">
                          {php Common::genExtendData($typeid,$extendinfo);}
                        </div>


                        <div class="clear clearfix pt-5 pb-20">
                          <input type="hidden" name="productid" id="productid" value="{$info['id']}"/>
                          <input type="hidden" name="action" id="action" value="{$action}"/>
                          <input type="hidden" name="webid" id="webid" value="0"/>
                          <a class="btn btn-primary radius size-L ml-115" id="btn_save" href="javascript:;">保存</a>
                        </div>

                    </div>

                </form>
            </td>
        </tr>
    </table>

	<script>
        //保存状态
        window.is_saving = 0;

        //获取下级分类
        function getCategoryNext(categoryId,isPid){
            if(categoryId==0)
            {
                $("#category_two").empty();
                $("#category_two").parent().hide();
                return ;
            }
            $.ajax({
                type:'POST',
                url:  SITEURL+"news/admin/news/ajax_get_category_next",
                data:{category_id:categoryId,is_pid:isPid},
                dataType:'json',
                success:function(data){
                    if(data.status){
                        $("#category_two").empty();
                        if(data.list.length>0)
                        {
                            $("#category_two").parent().show();
                        }
                        else
                        {
                            $("#category_two").parent().hide();
                        }


                        $.each(data.list,function(i,obj){
                            var value = obj.id;
                            var text= obj.attrname;
                            var selected = isPid==0 && obj.id == categoryId ? "selected='selected'" : '';
                            $("#category_two").append("<option value='"+value+"' "+selected+">"+text+"</option>");
                        })


                    }
                }
            })
        }


	$(document).ready(function(){

        $("#nav").find('span').click(function(){

            Product.changeTab(this,'.product-add-div');//导航切换
        })
        $("#nav").find('span').first().trigger('click');


        var action = "{$action}";
        //上传图片

        $('#pic_btn').click(function(){
            ST.Util.showBox('上传图片', SITEURL + 'image/insert_view', 0,0, null, null, document, {loadWindow: window, loadCallback: Insert});
            function Insert(result,bool){
                var len=result.data.length;
                for(var i=0;i<len;i++){
                    var temp =result.data[i].split('$$');
                    Imageup.genePic(temp[0],".up-list-div ul",".cover-div");
                }
            }
        });

        // 上传附件
        $('#attach_btn').click(function(){
            $.upload({
                // 上传地址
                url: SITEURL+'uploader/uploaddoc',
                // 文件域名字
                fileName: 'Filedata',
                fileType: 'doc,docx,pdf',
                // 其他表单数据
                params: {uploadcookie:"<?php echo Cookie::get('username')?>"},
                // 上传完成后, 返回json, text
                dataType: 'json',
                // 上传之前回调,return true表示可继续上传
                onSend: function() {
                    return true;
                },
                // 上传之后回调
                onComplate: function(info) {
                    if(info.status){
                        if(info.status){
                           var html = '<a href="'+info.path+'" target="_blank">查看附件</a>&nbsp;';
                           $("#attachment").val(info.path);
                           if(action=='edit'){
                               html+= '<a href="javascript:;" onclick="delAttach()">删除</a>';
                           }

                           $("#doclist").html(html);
                        }
                    }
                }
            });
        })

        //保存
        $("#btn_save").click(function(){

            //检测是否是在保存状态
            if(is_saving == 1){
                return false;
            }
            window.is_saving = 1;
            var articlename = $("#articlename").val();

            //验证名称
             if(articlename==''){
                   $("#nav").find('span').first().trigger('click');
                   $("#articlename").focus();
                   ST.Util.showMsg('请填写资讯名称',5,2000);
               }
               else
               {
                   $.ajaxform({
                       url   :  SITEURL+"news/admin/news/ajax_save",
                       method  :  "POST",
                       isUpload :  true,
                       form  : "#product_frm",
                       dataType  :  "JSON",
                       success  :  function(data)
                       {

                           //var data = $.parseJSON(response.responseText);
                           if(data.status)
                           {
                               if(data.productid!=null){
                                   $("#productid").val(data.productid);
                               }
                               ST.Util.showMsg('保存成功!','4',2000);
                           }
                           window.is_saving = 0;


                       }});
               }

        })


        //如果是修改页面


        {if $action=='edit'}
            var piclist = ST.Modify.getUploadFile({$info['piclist_arr']});
            $(".pic-sel").html(piclist);
            var litpic = $("#litpic").val();
            $(".img-li").find('img').each(function(i,item){
                if($(item).attr('src')==litpic){
                    var obj = $(item).parents('.img-li').first().find('.btn-ste')[0];
                    Imageup.setHead(obj,i+1);
                }
            })
            window.image_index= $(".pic-sel").find('li').length;//已添加的图片数量
                $('input[name="allow"]').click(function(){
                    if($(this).is(':checked')){
                        ST.Util.confirmBox('提取封面图','如果已提取过封面再次从内容中提取封面图可能造成图片重复,确认要再次提取?',function(){},function(){
                            $('input[name="allow"]').attr('checked',false);
                        })
                    }
                })
        {/if}






     });

     function showpic()
     {
         $("#updiv").show();
     }
     function unshowpic()
     {
         $("#updiv").hide();
     }

     function delAttach()
     {
                var articleid = '{$info['id']}';
                $.ajax({
                    type:'POST',
                    url:SITEURL+'news/admin/news/ajax_del_attach',
                    data:{articleid:articleid},
                    dataType:'json',
                    success:function(data){
                        if(data.status){
                            $("#doclist").html('');
                            ST.Util.showMsg('删除成功',4,1000);

                        };
                    }
                })
      }



    </script>

</body>
</html>
